package com.algorithm.array;

import com.algorithm.array.interfaces.impl.ArrayList;

import java.util.Scanner;

/**
 * 单元测试方法
 */
public class main {
    public static void main(String[] args) {
        scannerArrayListTest();
    }

    public static void scannerArrayListTest(){
        Scanner scanner = new Scanner(System.in);
        boolean loop=true;
        System.out.println("请开始你的表演");
        System.out.println("输入 init 初始化容器");
        System.out.println("输入 add 往容器中追加");
        System.out.println("输入 get 容容器中获取下标i数据");
        System.out.println("输入 rm  删除容器中某个数据");
        System.out.println("输入 put 往容器中替换数据");
        System.out.println("输入 insert 往容器中插入数据");
        System.out.println("输入 size 查看容量");
        System.out.println("输入 isEmpty 查看容器是否为空");
        System.out.println("输入 indexOf 查看容器是否为空");
        String input;
        int scannerIndex;
        int scannerValue;
        ArrayList list = null;
        while (loop){
            if(list!=null){
                System.out.println(list.toString());
            }
            input= scanner.nextLine();
            switch (input){
                case "init":
                    list=new ArrayList(3);
                    System.out.printf("初始化完成");
                    break;
                case "add":
                    scannerIndex=Integer.parseInt(scanner.nextLine());
                    list.add(scannerIndex);
                    break;
                case "get":
                    scannerIndex=Integer.parseInt(scanner.nextLine());
                    System.out.printf(String.valueOf(list.get(scannerIndex)));
                    break;
                case "rm":
                    scannerIndex=Integer.parseInt(scanner.nextLine());
                    System.out.printf(String.valueOf(list.remove(scannerIndex)));
                    break;
                case "size":
                    System.out.printf("容器容量是："+list.getSize());
                    break;
                case "insert":
                    scannerIndex=Integer.parseInt(scanner.nextLine());
                    scannerValue=Integer.parseInt(scanner.nextLine());
                    System.out.printf(String.valueOf(list.insert(scannerIndex,scannerValue)));
                    break;
                case "indexOf":
                    scannerIndex=Integer.parseInt(scanner.nextLine());
                    System.out.printf(String.valueOf(list.indexOf(scannerIndex)));
                    break;
                case "结束":
                    loop=false;
                    break;
            }
        }

    }
}
